def isPalindromic(number)
    return number.to_s == number.to_s.reverse
end

def isBinaryPalindromic(number)
    return number.to_s(base=2) == number.to_s(base=2).reverse
end

sum = 0
(0..999999).each do |number|
    if isPalindromic(number) && isBinaryPalindromic(number)
        puts number.to_s + " " + number.to_s(base=2)
        sum += number
    end
end

puts sum